<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row class="form-row" :gutter="1">
          <a-col :lg="12">
            <a-form-item label="户主姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'loanName', validatorRules.loanName]" placeholder="请输入户主姓名"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="乡镇" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['fwzId',validatorRules.fwzId]" :trigger-change="true"
                                 dictCode="tb_jrtx_fwz,township_name,id" placeholder="请选择乡镇"/>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row class="form-row" :gutter="1">
          <a-col :lg="12">
            <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['sex',validatorRules.sex]" :trigger-change="true" dictCode="sex"
                                 placeholder="请选择性别"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="年龄" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'age', validatorRules.age]" placeholder="请输入年龄"></a-input>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row class="form-row" :gutter="1">
          <a-col :lg="12">
            <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'idNumber', validatorRules.idNumber]" placeholder="请输入身份证号"></a-input>
            </a-form-item>
          </a-col>
            <a-col :lg="12">
              <a-form-item label="家庭住址" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="[ 'address', validatorRules.address]" placeholder="请输入家庭住址"></a-input>
              </a-form-item>
            </a-col>
        </a-row>
        <a-row class="form-row" :gutter="1">
          <a-col :lg="12">
            <a-form-item label="信用等级" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['creditRating',validatorRules.creditRating]" :trigger-change="true" dictCode="credit_rating"
                                 placeholder="请选择信用等级"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="信用评分" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'creditScore', validatorRules.creditScore]" placeholder="请输入信用评分"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="1">
          <a-col :lg="12">
              <a-form-item label="借款金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-tooltip>
                  <template slot="title">
                    5万格式：5  &nbsp &nbsp     单位:万元
                  </template>
                  <a-input v-decorator="[ 'loanMoney', validatorRules.loanMoney]" placeholder="请输入借款金额"></a-input>
                </a-tooltip>

              </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="借款用途" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'loanUse', validatorRules.loanUse]" placeholder="请输入借款用途"></a-input>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row class="form-row" :gutter="1">
          <a-col :lg="12">
            <a-form-item label="批次" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-tooltip>
                <template slot="title">
                  第7批次格式：7
                </template>
                <a-input v-decorator="[ 'batch', validatorRules.batch]" placeholder="请输入批次"></a-input>
              </a-tooltip>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="公示时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择公示时间" v-decorator="[ 'dateGs', validatorRules.dateGs]" :trigger-change="true"
                      style="width: 100%"/>
            </a-form-item>
          </a-col>
        </a-row>

         <!-- <a-form-item label="流程id" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="[ 'processId', validatorRules.processId]" placeholder="请输入批次"></a-input>
          </a-form-item>-->

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

    import {httpAction,getAction} from '@/api/manage'
    import pick from 'lodash.pick'
    import JDate from '@/components/jeecg/JDate'

    export default {
        name: "SmallAmountPublicityAccountModal",
        components: {
            JDate
        },
        data() {
            return {
                processId:"",
                form: this.$form.createForm(this),
                title: "操作",
                width: 800,
                visible: false,
                model: {},
                labelCol: {
                    xs: {span: 24},
                    sm: {span: 5},
                },
                wrapperCol: {
                    xs: {span: 24},
                    sm: {span: 16},
                },

                confirmLoading: false,
                validatorRules: {
                    loanName: {rules: [{ required: true, message: '户主姓名不能为空'}]},
                    fwzId:{rules: [{ required: true, message: '乡镇不能为空'}]},
                    sex:{rules: [{ required: true, message: '性别不能为空'}]},
                    address:{rules: [{ required: true, message: '家庭住址不能为空'}]},
                    creditRating:{rules: [{ required: true, message: '信用等级不能为空'}]},
                    loanMoney:{rules: [{ required: true, message: '借款金额不能为空'}]},
                    loanUse:{rules: [{ required: true, message: '借款用途不能为空'}]},
                    age: {},
                    batch: {rules: [{ required: true, message: '批次不能为空'}]},
                    dateGs: {rules: [{ required: true, message: '公示时间不能为空'}]},
                    idNumber:{rules: [{ required: true, message: '身份证号不能为空'}]},
                },
                url: {
                    add: "/loanmanagement/smallAmountPublicityAccount/add",
                    edit: "/loanmanagement/smallAmountPublicityAccount/edit",
                    queryByProcessId:"/loanmanagement/smallAmountPublicityAccount/queryByProcessId",
                }

            }
        },
        created() {
        },
        methods: {
            add() {
                this.edit({});
            },
            edit(record) {
                this.form.resetFields();
                this.model = Object.assign({}, record);
                this.visible = true;
                this.$nextTick(() => {
                    this.form.setFieldsValue(pick(this.model, 'loanName','idNumber','fwzId','creditScore','sex', 'age', 'address','creditRating','loanMoney', 'loanUse', 'batch','processId','dateGs'))
                })
            },
            close() {
                this.$emit('close');
                this.visible = false;
            },
            handleOk() {
                const that = this;
                // 触发表单验证
                this.form.validateFields((err, values) => {
                    if (!err) {
                        that.confirmLoading = true;
                        let httpurl = '';
                        let method = '';
                        if (!this.model.id) {
                            httpurl += this.url.add;
                            method = 'post';
                        } else {
                            httpurl += this.url.edit;
                            method = 'put';
                        }
                        values.processId = this.processId;
                        let formData = Object.assign(this.model, values);
                        console.log("表单提交数据", formData)
                        httpAction(httpurl, formData, method).then((res) => {
                            if (res.success) {
                                that.$message.success(res.message);
                                that.$emit('ok');
                            } else {
                                that.$message.warning(res.message);
                            }
                        }).finally(() => {
                            that.confirmLoading = false;
                            that.close();
                        })
                    }

                })
            },
            handleCancel() {
                this.close()
            },
            popupCallback(row) {
                this.form.setFieldsValue(pick(row,'loanName','fwzId','idNumber','dateGs','sex', 'age','creditScore', 'address','creditRating','loanMoney', 'loanUse', 'batch','processId'))
            },
            showGoodsGallery1(record) {
                if(record){
                this.processId=record;
                const  that=this;
                var params={};
                params.processId=record;
                getAction(this.url.queryByProcessId, params).then((res) => {
                    if (res.success) {
                        that.$message.success("回显数据");
                        that.edit(res.result);
                    } else {
                        that.$message.warning("新增页面");
                    }
                    this.loading = false;
                })
                this.visible = true
            }

            }
        }
    }
</script>